package com.gz.EuchreU.Controls;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.input.touch.TouchEvent;

import com.gz.EuchreU.Contants.CardValues;
import com.gz.EuchreU.Contants.GameOptions;
import com.gz.EuchreU.Contants.Suits;
import com.gz.EuchreU.Contants.UI;
import com.gz.EuchreU.Sprite.Card;

public class RulesMenu extends MovingMenuEntity{

	private Card mLonerCard;
	private Text mLonerText;
	private Card mSTDCard;
	private Text mSTDText;
//	private Card mNoTrumpCard;
//	private Text mNoTrumpText;
//	private Card mFarmersHandCard;
//	private Text mFarmersHandText;
	private Card mPCanOrderCard;
	private Text mPCanOrderText;
	
	//TODO: POINTS TO WIN?
	private Card mPointsToWinCard;
	private Text mPointsToWinText;
	
	public RulesMenu(float pOnScreenX, float pOnScreenY, float pWidth,Scene pScene) {
		super(pOnScreenX, pOnScreenY, pWidth, true);

		float cardWidth = pWidth/15;
		float buttonX = pOnScreenX + 3*pWidth/4 - cardWidth;
		float buttonY = pOnScreenY + 30;
		float textX = pOnScreenX + pWidth/4 - cardWidth;
		
		float cardHeight = UI.getTextures().getHeightFromWidthTiled(0, 0, cardWidth);
		float textY = buttonY + cardHeight/3;	
		
		mLonerCard = GetAceOfSpades(buttonX, buttonY, cardWidth);
		mLonerText = GetText(textX, textY, "Allow Loners");
		textY += cardHeight + 2;
		buttonY += cardHeight + 2;
		mSTDCard = GetAceOfSpades(buttonX, buttonY, cardWidth);
		mSTDText = GetText(textX, textY, "Screw The Dealer");
		textY += cardHeight + 2;
		buttonY += cardHeight + 2;
//		mNoTrumpCard = GetAceOfSpades(buttonX, buttonY, cardWidth);
//		mNoTrumpText = GetText(textX, textY, "Allow Calling No Trump");
//		textY += cardHeight + 2;
//		buttonY += cardHeight + 2;
//		mFarmersHandCard = GetAceOfSpades(buttonX, buttonY, cardWidth);
//		mFarmersHandText = GetText(textX, textY, "Allow Farmers Hand");
//		textY += cardHeight + 2;
//		buttonY += cardHeight + 2;
		mPCanOrderCard = GetAceOfSpades(buttonX, buttonY, cardWidth);
		mPCanOrderText = GetText(textX, textY, "Dealers P Can Order");
//		textY += cardHeight + 2;
//		buttonY += cardHeight + 2;
//		mPointsToWinCard = GetAceOfSpades(buttonX, buttonY, cardWidth);
//		mPointsToWinText = GetText(textX, textY, "Points To Win");
		
		attachChild(mLonerCard);
		attachChild(mLonerText);
		attachChild(mSTDCard);
		attachChild(mSTDText);
//		attachChild(mNoTrumpCard);
//		attachChild(mNoTrumpText);
//		attachChild(mFarmersHandCard);
//		attachChild(mFarmersHandText);
		attachChild(mPCanOrderCard);
		attachChild(mPCanOrderText);
//		attachChild(mPointsToWinCard);
//		attachChild(mPointsToWinText);
		
		pScene.registerTouchArea(mLonerCard);
		pScene.registerTouchArea(mSTDCard);
//		pScene.registerTouchArea(mNoTrumpCard);
//		pScene.registerTouchArea(mFarmersHandCard);
		pScene.registerTouchArea(mPCanOrderCard);
//		pScene.registerTouchArea(mPointsToWinCard);
		
		LoadDefaults();
		
	}

	private void LoadDefaults(){
		mLonerCard.setDisabled(!GameOptions.GetBoolOption(GameOptions.PREF_BOOL_LONER));
		mSTDCard.setDisabled(!GameOptions.GetBoolOption(GameOptions.PREF_BOOL_STD));
//		mNoTrumpCard.setDisabled(!GameOptions.GetBoolOption(GameOptions.PREF_BOOL_CALL_NO_TRUMP));
//		mFarmersHandCard.setDisabled(!GameOptions.GetBoolOption(GameOptions.PREF_BOOL_FARMERS));
		mPCanOrderCard.setDisabled(!GameOptions.GetBoolOption(GameOptions.PREF_BOOL_DEALER_P_ORDER));
		//mPointsToWinCard.setDisabled(!GameOptions.Loner);
	}
	
	@Override
	public Card GetAceOfSpades(final float pX, final float pY, final float pWidth){
		return new Card(pX,pY,pWidth,Suits.SPADES,CardValues.ACE){
			@Override
			public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
					float pTouchAreaLocalX, float pTouchAreaLocalY) {
				if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){		
					
					if(this.getCardID() == mLonerCard.getCardID()){
						this.setDisabled(!this.getDisabled());
						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_LONER, !mLonerCard.getDisabled());
					}
					else if(this.getCardID() == mSTDCard.getCardID()){
						this.setDisabled(!this.getDisabled());
						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_STD, !mSTDCard.getDisabled());
					}
//					else if(this.getCardID() == mNoTrumpCard.getCardID()){
//						this.setDisabled(!this.getDisabled());
//						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_CALL_NO_TRUMP, !mNoTrumpCard.getDisabled());
//					}
//					else if(this.getCardID() == mFarmersHandCard.getCardID()){
//						this.setDisabled(!this.getDisabled());
//						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_FARMERS, !mFarmersHandCard.getDisabled());
//					}
					else if(this.getCardID() == mPCanOrderCard.getCardID()){
						this.setDisabled(!this.getDisabled());
						GameOptions.SetBoolOption(GameOptions.PREF_BOOL_DEALER_P_ORDER, !mPCanOrderCard.getDisabled());
					}
				}
				return true;
			}
		};
	}
	
}
